package com.comcast.core.eeg.eventpublication.service.ws;

import com.comcast.core.eeg.types.Event;
import com.comcast.core.eeg.types.NotificationRole;
import com.comcast.core.eeg.types.Participant;
import com.comcast.core.eeg.types.XMLEventDetails;

public class EventMapperImpl implements EventMapper {

    public Event createEvent(XmlEvent xml) {
        if (xml == null) {
            return null;
        }
        Event event = new Event();
        event.setEventName(xml.getEventName());
        EventProperty[] props = xml.getProperties();
        if (props != null) {
            for (int i = 0; i < props.length; i++) {
                event.setProperty(props[i].getName(), props[i].getValue());
            }
        }
        XmlEventDetails body = xml.getEventDetails();
        if (body != null) {
            XMLEventDetails details = new XMLEventDetails(body.getXml());
            event.setDetails(details);
        }
        return event;
    }
    
    public Event[] createEvents(XmlEvent[] xmls) {
        if (xmls == null) {
            return null;
        }
        
        Event[] events = new Event[xmls.length];
        for (int i = 0; i < xmls.length; i++) {
            events[i] = createEvent(xmls[i]);
        }
        return events;
    }
    
    public Participant createParticipant(String id) {
        Participant actor = new Participant();
        actor.setIdentifier(id);
        actor.setRole(NotificationRole.PUBLISHER);
        return actor;
    }

}
